// 状态变更
import React from "react";
import LlxForm from 'components/LlxForm/index'
import { Form ,notification,Modal} from 'antd';

import {setRemarkBacth} from 'api/index'


const ChangeStatus = (props) => {
  const {isModalVisible, setIsModalVisible,list,userName,http,type,statusType} = props

  const [form] = Form.useForm();

  const formItem = [
    {label: '留言',type:'textArea', name: 'remark' , span: 20 },
    {label: '', name: 'status' , span: 20 ,render:()=>{
      return  <div className="text-color-red">
      *  状态将回退至N / PN !
      </div>
    }}
  ]

  const handleOk = async () => {

    await http(
      list.map(item => {
        return {
        [statusType]:  ['N','R','Q'].includes(item[statusType])?'N':'PN',
          id: item.id,
          rmanager: '',
          qmanager: '',
          message: form.getFieldValue().remark
        }
      })
    )
   
    await setRemarkBacth(list.map(i => {
          return {
            manager: '',
            dataId: i.id,
            type: type,
            remark: form.getFieldValue().remark,
            statusNow: i[statusType],
            statusNext: ['N','R','Q'].includes(i[statusType])?'N':'PN'
          }
     }))

    notification.success({
      message: '回退成功',
      description: '操作人：' + userName,
      duration:1.5
    });

    form.resetFields()
    setIsModalVisible(false);
    props.getNewList()
 }

 const handleCancel = () => {
  form.resetFields()
  setIsModalVisible(false);
};

return   <Modal width={800} title="状态变更" visible={isModalVisible} onOk={handleOk} onCancel={handleCancel}>
      <LlxForm form={form} labelCol={8} formItem={formItem} />
 </Modal>
}

export default ChangeStatus